﻿using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using Path = System.IO.Path;

namespace ScriptBox
{
    /// <summary>
    /// ButtonEditor.xaml 的交互逻辑
    /// </summary>
    public partial class ButtonEditor : UserControl
    {
        public ButtonEditor()
        {
            InitializeComponent();
        }

        private void BrowseImage_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new OpenFileDialog
            {
                Filter = "图片文件|*.png;*.jpg;*.bmp"
            };

            if (dialog.ShowDialog() == true)
            {
                ((AI_ScriptButton)DataContext).ImgPath = dialog.FileName;
            }
        }


        private void Browsepath_Click(object sender, RoutedEventArgs e)
        {
            if (((AI_ScriptButton)DataContext).ScriptType == "file")
            {
                var dialog = new OpenFileDialog();

                if (dialog.ShowDialog() == true)
                {
                    ((AI_ScriptButton)DataContext).ScriptContent = dialog.FileName;
                }

            }
            else if (((AI_ScriptButton)DataContext).ScriptType == "dir")
            {
                var dialog = new OpenFolderDialog();
                if (dialog.ShowDialog() == true)
                {
                    ((AI_ScriptButton)DataContext).ScriptContent = dialog.FolderName;
                }
            }
            else if (((AI_ScriptButton)DataContext).ScriptType == "exe" || ((AI_ScriptButton)DataContext).ScriptType == "python")
            {
                var dialog = new OpenFileDialog();

                if (dialog.ShowDialog() == true)
                {
                    ((AI_ScriptButton)DataContext).ScriptContent = dialog.FileName;
                }

            }
        }

        private void TypeChanged(object sender, SelectionChangedEventArgs e)
        {
            if (((AI_ScriptButton)DataContext).ScriptType == "file" || ((AI_ScriptButton)DataContext).ScriptType == "dir" || ((AI_ScriptButton)DataContext).ScriptType == "exe"
                || ((AI_ScriptButton)DataContext).ScriptType == "python")
            {
                Content_Text.Visibility = Visibility.Hidden;
                ContentPath_button.Visibility = Visibility.Visible;
                ContentPath_Text.Visibility = Visibility.Visible;
            }
            else
            {
                Content_Text.Visibility = Visibility.Visible;
                ContentPath_button.Visibility = Visibility.Hidden;
                ContentPath_Text.Visibility = Visibility.Hidden;
            }
        }
    }
}
